import { Provide } from '@midwayjs/core';
import {RepairItem} from "../entity/repairItem.entity"

@Provide()
export class RepairItemService {
  async getList() {
    const list = await RepairItem.findAll({
      order:[['id','DESC']]
    });
    return list;
  }

  async addItem(name:string) {
    const result = await RepairItem.findOrCreate({
      where: { name },
      defaults: {
        name
      },
      attributes:{exclude:['createdAt']}
    })
    return result
  }

  async editItem(id:number,name:string) {
    const result = await RepairItem.update({ name }, {
      where: {
        id
      }
    })
    return result
  }

  async delItem(id:number) {
    const result = await RepairItem.destroy({
      where: {
        id
      }
    })
    return result
  }
}
